import React, { Component } from 'react'
import Cmp1 from './components/Cmp1'
import Cmp2 from './components/Cmp2'
import Store from './store'

// context出现为了解决多层组件之间的通信问题
// 统一数据源
// App组件是react项目中的根组件，所有的子组件都在此
export default class App extends Component {

  state = {
    count: 1,
    setCount: () => {
      this.setState(state => {
        return {
          count: ++state.count
        }
      })
    }
  }


  render() {
    let { count, setCount } = this.state
    return (
      <div>
        <Store.Provider value={{ count, setCount }}>
          {/* 兄弟 */}
          <Cmp1></Cmp1>
          <Cmp2></Cmp2>
        </Store.Provider>
      </div>
    )
  }

}
